package com.xidian.zhiancloud.controller.equipFacility.defendManager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.dto.equipFacility.DefendRegisterDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.DefendRegister;
import com.xidian.zhiancloud.qo.equipFacility.DefendRegisterQO;
import com.xidian.zhiancloud.service.equipFacility.DefendRegisterService;
import com.xidian.zhiancloud.vo.equipFacility.DefendRegisterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

/**
 * 设备设施 维护管理 维护登记接口
 *
 * @Author: 任启亮
 * @Date: 2020/11/12
 */
@RestController
@RequestMapping("/DefendRegister")
public class DefendRegisterController extends BaseController {

    @Autowired
    private DefendRegisterService defendRegisterService;

    /**
     * 添加维护登记信息
     * @param defendRegisterDTO 请求参数
     * @return 返回是否添加成功
     */
    @RequestMapping("/add")
    public ResultDTO<Boolean> add(DefendRegisterDTO defendRegisterDTO){
        defendRegisterDTO.getDefendRegister().setCompanyId(getSessionUserCompanyId());
        defendRegisterDTO.getDefendRegister().setCreateTime(new Date(System.currentTimeMillis()));
        defendRegisterDTO.getDefendRegister().setCreator(getSessionUserid());
        return ResultDTO.successOf(defendRegisterService.add(defendRegisterDTO),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除维护登记记录
     * @param ids 维护登记id列表
     * @return 返回是否删除成功
     */
    @RequestMapping("/deleteByIds")
    public ResultDTO<Boolean> deleteByIds(Long[] ids){
        return ResultDTO.successOf(defendRegisterService.deleteByIds(ids),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 更新维护登记信息
     * @param defendRegisterDTO
     * @return
     */
    @RequestMapping("/patchById")
    public ResultDTO<Boolean> patchById(DefendRegisterDTO defendRegisterDTO){
        defendRegisterDTO.getDefendRegister().setCreateTime(null);
        defendRegisterDTO.getDefendRegister().setCreator(null);
        defendRegisterDTO.getDefendRegister().setCompanyId(null);
        return ResultDTO.successOf(defendRegisterService.patchById(defendRegisterDTO),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id查询
     * @param id 维护登记id
     * @return 返回维护登记信息
     */
    @GetMapping("/getById")
    public ResultDTO<DefendRegisterVO> getById(Long id){
        return ResultDTO.successOf(defendRegisterService.getById(id),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 列表查询
     * @param defendRegisterQO 请求参数
     * @return 返回查询结果  列表
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<DefendRegisterVO>> getListByQO(DefendRegisterQO defendRegisterQO){
        defendRegisterQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(defendRegisterService.getListByQO(defendRegisterQO),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 提交
     * @param id 维护登记id
     * @return 返回是否提交成功
     */
    @GetMapping("/submit")
    public ResultDTO<Boolean> submit(Long id){
        return ResultDTO.successOf(defendRegisterService.submit(id),GeneralResponseEnums.SUCCESS);
    }
}
